﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class BaseEnermy : MonoBehaviour
{
    /// <summary>
    /// 怪物的种类
    /// </summary>
    public enum Type
    {
        None,
        Mushroom,
        Tortoise,
        Flower
    }

    [EnumFlags,SerializeField]
    private EVENT_TYPE Event_Types;

    #region 基础数据
    [Header("基础数值")]
    [SerializeField]
    [Tooltip("血量")]
    protected int _hp;
    protected bool isDying=false;
    public int HP
    {
        set
        {
            if (value > 0)
            {
                _hp = value;
                return;
            }
            if(!isDying)
            {
                isDying=true;
                Dead();
            }
        }

        get
        {
            return _hp;
        }
    }

    [SerializeField]
    [Tooltip("行进速度")]
    protected float speed;
    [Header("怪物种类")]
    [SerializeField]
    [Tooltip("怪物种类")]
    protected Type type;
    public Type TheType
    {
        get
        {
            return type;
        }
    }
    #endregion

    #region 基础函数

    /// <summary>
    /// 攻击函数
    /// </summary>
    protected abstract void Attack();

    /// <summary>
    /// 死亡函数
    /// </summary>
    protected abstract void Dead();

    /// <summary>
    /// 移动函数
    /// </summary>
    protected abstract void Move();

    protected abstract void OnMyEvent(EVENT_TYPE Event_Type,
        Component Sender, object Param = null);

    private void Start()
    {
        foreach (EVENT_TYPE t in System.Enum.GetValues(typeof(EVENT_TYPE)))
        {
            if ((t & Event_Types) == t)
                EventManager.Instance.AddListener(t, OnMyEvent);
        }
    }

    #endregion

}
